package com.imcode;

import java.io.*;

public class FileCopy01 {

    /**
     * 将file/1.txt 复制到 file/2.txt
     *
     * @param args
     */
    public static void main(String[] args) throws IOException {
        long t1 = System.currentTimeMillis();
        //1.读取1.txt到内容
        InputStream in = new FileInputStream("file/1.exe");
        OutputStream out = new FileOutputStream("file/2.exe");
        //2.按字节数组数组读取文件内容
        byte[] bytes = new byte[1024];
        //3.循环读取文件内容
        int len = 0; // 存储每次读取到的字节的个数
        while ((len = in.read(bytes)) != -1) {
            //4.将读取到的内容写入到2.txt
            out.write(bytes,0,len);
        }
        //5.关闭流
        out.close();
        in.close();
        long t2 = System.currentTimeMillis();

        long time = (t2 - t1)/1000;

        System.out.println("基本字节流复制文件:" + time + "s");
    }
}
//基本字节流复制文件:12s